package o;

import android.text.TextUtils;
import com.huawei.hms.framework.common.ContainerUtils;
import com.huawei.hms.support.api.entity.pay.HwPayConstant;
import com.huawei.hms.support.api.pay.ProductPayResultInfo;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.Signature;
import java.security.SignatureException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ecj {
    public static boolean ॱ(ProductPayResultInfo productPayResultInfo, String str) {
        Map hashMap = new HashMap();
        hashMap.put("returnCode", Integer.valueOf(productPayResultInfo.getReturnCode()));
        hashMap.put(HwPayConstant.KEY_MERCHANTID, productPayResultInfo.getMerchantId());
        hashMap.put(HwPayConstant.KEY_REQUESTID, productPayResultInfo.getRequestId());
        hashMap.put(HwPayConstant.KEY_PRODUCT_NO, productPayResultInfo.getProductNo());
        hashMap.put("microsAmount", Long.valueOf(productPayResultInfo.getMicrosAmount()));
        hashMap.put(HwPayConstant.KEY_CURRENCY, productPayResultInfo.getCurrency());
        hashMap.put(HwPayConstant.KEY_COUNTRY, productPayResultInfo.getCountry());
        hashMap.put("time", productPayResultInfo.getTime());
        hashMap.put("orderID", productPayResultInfo.getOrderID());
        hashMap.put("errMsg", productPayResultInfo.getErrMsg());
        boolean ˊ = ˊ(ˋ(hashMap), productPayResultInfo.getSign(), str);
        Logger.ˎ("PayResultUtil", "ProductPayResultInfo Result Sign Check:" + ˊ);
        return ˊ;
    }

    private static boolean ˊ(String str, String str2, String str3) {
        try {
            PublicKey generatePublic = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(dnk.ˎ(str3)));
            Signature instance = Signature.getInstance("SHA256WithRSA");
            instance.initVerify(generatePublic);
            instance.update(str.getBytes("UTF-8"));
            return instance.verify(dnk.ˎ(str2));
        } catch (InvalidKeySpecException e) {
            Logger.ˋ("PayResultUtil", "doCheck payResult Failed. InvalidKeySpecException");
            return false;
        } catch (NoSuchAlgorithmException e2) {
            Logger.ˋ("PayResultUtil", "doCheck payResult Failed. NoSuchAlgorithmException");
            return false;
        } catch (InvalidKeyException e3) {
            Logger.ˋ("PayResultUtil", "doCheck payResult Failed. InvalidKeyException");
            return false;
        } catch (SignatureException e4) {
            Logger.ˋ("PayResultUtil", "doCheck payResult Failed. SignatureException");
            return false;
        } catch (UnsupportedEncodingException e5) {
            Logger.ˋ("PayResultUtil", "doCheck payResult Failed. UnsupportedEncodingException");
            return false;
        }
    }

    private static String ˋ(Map<String, Object> map) {
        StringBuilder stringBuilder = new StringBuilder();
        List arrayList = new ArrayList(map.keySet());
        Collections.sort(arrayList);
        for (int i = 0; i < arrayList.size(); i++) {
            String str = (String) arrayList.get(i);
            if (!HwPayConstant.KEY_SIGN.equals(str)) {
                Object obj = map.get(str);
                if (obj == null) {
                    obj = "";
                } else if (obj instanceof String) {
                    String str2 = (String) obj;
                } else {
                    obj = String.valueOf(obj);
                }
                if (!TextUtils.isEmpty(obj)) {
                    String str3;
                    if (i == 0) {
                        str3 = "";
                    } else {
                        str3 = ContainerUtils.FIELD_DELIMITER;
                    }
                    stringBuilder.append(str3).append(str).append(ContainerUtils.KEY_VALUE_DELIMITER).append(obj);
                }
            }
        }
        return stringBuilder.toString();
    }
}
